<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  request.setAttribute("now",new Date());
%>

<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading">
                <h3 class="panel-title">资产维修登记表</h3>
            </div>

            <!-- BASIC FORM ELEMENTS -->
            <!--===================================================-->
            <form id="form_assetmaintain_input" class="panel-body form-horizontal form-padding">
                <input type="hidden" name="keyId" id="keyId" value="${assetMaintain.id}" />

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_asset_dialog_select('name','assetId')" style="color: #0a6dbd">资产名称</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="name" name="name" class="form-control" value="${assetMaintain.name}" disabled>
                        <input type="hidden" name="assetId" id="assetId" value="${assetMaintain.asset.id}" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">资产编号<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="assetNo" name="assetNo" class="form-control" value="${assetMaintain.asset.assetNo}" disabled>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">资产品牌<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="brand" name="brand" class="form-control" value="${assetMaintain.asset.brand}" disabled>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">规则型号<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="model" name="model" class="form-control" value="${assetMaintain.asset.model}" disabled>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        维修原因
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="maintainReason" name="maintainReason" class="form-control" placeholder="请输入维修原因" value="${assetMaintain.maintainReason}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        维修单位
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="maintainUnit" name="maintainUnit" class="form-control" placeholder="请输入维修原因" value="${assetMaintain.maintainUnit}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        维修结果
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <div class="radio">
                            <input type="radio" name="maintainResult" id="maintainResult1Selected" class="magic-radio" value="0"
                            <c:if test="${assetMaintain.maintainResult eq 0}"> checked="checked"</c:if> >
                            <label for="maintainResult1Selected">维修完成</label>

                            <input type="radio" name="maintainResult" id="maintainResult2Selected" class="magic-radio" value="1"
                            <c:if test="${assetMaintain.maintainResult eq 1}"> checked="checked"</c:if> >
                            <label for="maintainResult2Selected">无法修复</label>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        维修费用（元）
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="number" id="maintainMoney" name="maintainMoney" class="form-control" placeholder="请输入维修费用" value="${assetMaintain.maintainMoney}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">提交人</label>
                    <div class="col-md-2">
                        <p class="form-control-static">${assetMaintain.creater.name}</p>
                    </div>
                    <label class="col-md-2 control-label">提交日期</label>
                    <div class="col-md-2">
                        <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${assetMaintain.dateApply}" /></p>
                    </div>
                </div>

            </form>
            <!--===================================================-->
            <!-- END BASIC FORM ELEMENTS -->

            <div class="panel-footer">
                <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                    <i class="fa fa-lg fa-mail-reply"></i> 返回视图
                </a>
                <c:if test="${assetMaintain.numStatus==0}">
                    <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存表单 </a>
                    <a class="btn btn-warning" id="btn-submit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交表单 </a>
                </c:if>
            </div>

        </div>
    </div>
</div>

<script>
    // 资产选择框
    function fn_asset_dialog_select(nameField,idField) {
        __open_dialog_select('选择资产', '<%=path%>/activiti/asset/dialogs?category=3', function (dialogRef) {
            var callback = function (data) {
                if (data) {
                    dialogRef.close();

                    // 获取 user
                    $('#'+idField).val(data.id);
                    $('#'+nameField).val(data.name);

                    $('#assetNo').val(data.assetNo);
                    $('#brand').val(data.brand);
                    $('#model').val(data.model);
                } else {
                    dialogRef.enableButtons();
                }
            };
            fn_dialog_asset_select(callback);
        });
    }

    //校验
    function infoValidate() {
        var tmp = "";

        tmp = $("input#assetId").val();
        if(!tmp){
            __toastr_error("请选择资产！");
            return false;
        }

        tmp = $("input#maintainReason").val();
        if(!tmp){
            __toastr_error("请输入维修原因！");
            return false;
        }

        tmp = $("input#maintainUnit").val();
        if(!tmp){
            __toastr_error("请输入维修单位！");
            return false;
        }

        tmp = $("input#maintainMoney").val();
        if(!tmp){
            __toastr_error("请输入维修费用！");
            return false;
        }

        return true;
    }

    //保存
    $("#btn-save-common").click(
        function(e) {
            __confirm_dialog("提示：","确定保存吗？",
                function () {
                    __form_save("form_assetmaintain_input", "<%=path%>/activiti/assetmaintain/save");
                    returnToHashUrl();
                }
            )
        }
    );

    //提交
    $("#btn-submit-common").click(
        function(e) {
            var $valid = infoValidate();
            if(!$valid) return false;

            __confirm_dialog("提示：","提交后填写资料不得修改，请确认是否进行提交？",
                function () {
                    __form_save("form_assetmaintain_input", "<%=path%>/activiti/assetmaintain/submit");
                    returnToHashUrl();
                }
            )
        }
    );
    //返回视图
    $("#apply-re-common").click(returnToHashUrl);

    // 加载完成后执行
    $(function(){
       

    })

</script>
